import numpy as np

data = np.loadtxt(r'ex1data2.txt', delimiter=',')
x = data[:, :-1]
y = data[:, -1:]
# print(x.shape)
# print(y.shape)

# 特征缩放
sigma = x.std(axis=0, ddof=1)
mu = x.mean(axis=0)
x = (x - mu) / sigma

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

#使用sequential创建模型
model = Sequential()
'''
input_dim=2
a = tf.placeholder(None, 2)
y = w * a + b
'''
#模型中添加dense层：输入维度input_dim=2, 单元个数=1
model.add(Dense(1, input_dim=2))
# 模型配置
model.compile(optimizer='Adam', loss='mse')
# 模型训练
model.fit(x, y, epochs=1000)
# 预测模型
print(model.predict(x))
